import Cookies from 'js-cookie'
import CryptoJS from 'crypto-js'
const TokenKey = 'Token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export const authMap = {

}
// 去登录
export function gotoLogin() {
  const redirectUrl = window.location.href
  const url = `${process.env.VUE_APP_LOGIN_URL}?redirect_url=${redirectUrl}&appid=${process.env.VUE_APP_APPID}&login_way=ap,ding_talk,wc_talk`
  location.replace(url)
}

// 去登录
export function gotoAuthLogin(redirectUrl) {
  redirectUrl = redirectUrl || window.location.href
  const backUrl = `${location.protocol}//${location.hostname}${location.port ? (':' + location.port) : ''}/auth?redirect_url=${redirectUrl}`
  const url = `${process.env.VUE_APP_LOGIN_URL}?redirect_url=${backUrl}&appid=${process.env.VUE_APP_APPID}&login_way=ap,ding_talk,wc_talk`
  location.replace(url)
}

// aes 加密
export function aesEncrypt(word) {
  var encrypt = CryptoJS.AES.encrypt(
    word.toString(),
    CryptoJS.enc.Utf8.parse('XIli#Lka5YYm1xwd^#3W@$JV!y2yG9$e' || ''),
    {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    }
  )
  return encrypt.toString()
}
